﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing;
using GeckoPhotos.Tests.Util;

namespace GeckoPhotos.Tests.Support
{

    [TestClass]
    public class ImageCsvUtil
    {

        [TestMethod]
        public void GetMoon32x32AsCsv()
        {
            string csv = ImageToPngCsv(Properties.Resources.Moon32x32);
            System.Console.Out.WriteLine(csv);
        }

        [TestMethod]
        public void GetMoon64x64AsCsv()
        {
            string csv = ImageToPngCsv(Properties.Resources.moon64x64);
            System.Console.Out.WriteLine(csv);
        }

        [TestMethod]
        public void GetCroc640x360AsCsv()
        {
            string csv = ImageToPngCsv(Properties.Resources.Croc640x360);
            System.Console.Out.WriteLine(csv);
        }

        public static string ImageToPngCsv(Image image)
        {
            using (var ms = new System.IO.MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                return CSVUtil.MemoryStreamToByteCSV(ms);
            }
        }

        [TestMethod]
        public void ImageToPngCsvWithMoon32x32ReturnsExpectedResult()
        {
            // Precomputed result for calling ImageToPngCsv(Properties.Resources.Moon32x32).  If the 
            //  Moon32x32 image is ever updated, this test will need to be updated to suit.
            const string expectedString = "137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 32, 0, 0, 0, 32, 8, 3, 0, 0, 0, 68, 164, 138, 198, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 32, 99, 72, 82, 77, 0, 0, 122, 38, 0, 0, 128, 132, 0, 0, 250, 0, 0, 0, 128, 232, 0, 0, 117, 48, 0, 0, 234, 96, 0, 0, 58, 152, 0, 0, 23, 112, 156, 186, 81, 60, 0, 0, 3, 0, 80, 76, 84, 69, 0, 0, 0, 1, 1, 1, 2, 2, 1, 2, 2, 2, 3, 3, 3, 4, 3, 2, 5, 4, 4, 5, 5, 5, 7, 6, 5, 6, 6, 6, 7, 7, 7, 8, 5, 4, 8, 6, 4, 9, 7, 6, 11, 9, 7, 12, 9, 7, 8, 8, 8, 9, 9, 9, 11, 11, 11, 13, 10, 8, 12, 11, 10, 15, 13, 12, 14, 14, 14, 18, 13, 9, 16, 12, 11, 19, 14, 11, 18, 14, 12, 21, 15, 12, 18, 16, 14, 21, 17, 14, 16, 16, 16, 18, 18, 17, 18, 18, 18, 19, 19, 19, 20, 19, 19, 21, 20, 20, 27, 24, 22, 24, 24, 24, 26, 25, 25, 26, 26, 26, 27, 27, 27, 28, 26, 25, 28, 28, 28, 28, 28, 29, 34, 27, 22, 35, 28, 23, 35, 29, 26, 32, 29, 27, 37, 31, 26, 36, 31, 29, 33, 32, 31, 42, 35, 30, 32, 32, 32, 34, 34, 34, 36, 36, 36, 37, 37, 37, 39, 39, 39, 43, 40, 37, 42, 40, 39, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 45, 45, 45, 46, 46, 46, 50, 49, 47, 49, 49, 49, 50, 50, 50, 51, 51, 51, 53, 51, 49, 54, 52, 50, 52, 52, 52, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 58, 58, 58, 60, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 66, 66, 66, 66, 66, 67, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 72, 68, 67, 72, 72, 72, 73, 73, 73, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77, 77, 78, 78, 78, 79, 79, 79, 80, 80, 80, 81, 81, 81, 82, 82, 82, 83, 83, 83, 84, 84, 84, 85, 85, 85, 86, 86, 86, 87, 87, 87, 88, 88, 88, 89, 89, 89, 90, 90, 90, 91, 91, 91, 92, 92, 92, 93, 93, 93, 94, 94, 94, 95, 95, 95, 96, 96, 96, 97, 97, 97, 99, 99, 99, 100, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, 103, 104, 104, 104, 105, 105, 105, 106, 106, 106, 107, 107, 107, 108, 108, 108, 109, 109, 109, 110, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 117, 117, 117, 118, 118, 118, 119, 119, 119, 120, 120, 120, 121, 121, 121, 122, 122, 122, 123, 123, 123, 124, 124, 124, 125, 125, 125, 126, 126, 126, 127, 127, 127, 128, 128, 128, 129, 129, 129, 130, 130, 130, 131, 131, 131, 132, 132, 132, 133, 133, 133, 134, 134, 134, 135, 135, 135, 136, 136, 136, 137, 137, 137, 138, 138, 138, 139, 139, 139, 140, 140, 140, 141, 141, 141, 142, 142, 142, 143, 143, 143, 144, 144, 144, 146, 146, 146, 147, 147, 147, 148, 148, 148, 149, 149, 149, 150, 150, 150, 151, 151, 151, 152, 152, 152, 153, 153, 153, 154, 154, 154, 155, 155, 155, 156, 156, 156, 157, 157, 157, 158, 158, 158, 159, 159, 159, 160, 160, 160, 161, 161, 161, 162, 162, 162, 163, 163, 163, 164, 164, 164, 165, 165, 165, 166, 166, 166, 167, 167, 167, 168, 168, 168, 169, 169, 169, 170, 170, 170, 171, 171, 171, 172, 172, 172, 173, 173, 173, 174, 174, 174, 175, 175, 175, 176, 176, 176, 177, 177, 177, 178, 178, 178, 179, 179, 179, 180, 180, 180, 181, 181, 181, 182, 182, 182, 183, 183, 183, 184, 184, 184, 185, 185, 185, 186, 186, 186, 188, 188, 188, 189, 189, 189, 190, 190, 190, 191, 191, 191, 192, 192, 192, 193, 193, 193, 194, 194, 194, 195, 195, 195, 196, 196, 196, 197, 197, 197, 198, 198, 198, 199, 199, 199, 202, 202, 202, 203, 203, 203, 204, 204, 204, 205, 205, 205, 208, 208, 208, 209, 209, 209, 222, 222, 222, 236, 236, 236, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 157, 168, 10, 122, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 46, 34, 0, 0, 46, 34, 1, 170, 226, 221, 146, 0, 0, 2, 224, 73, 68, 65, 84, 56, 79, 99, 96, 64, 1, 44, 2, 92, 204, 168, 34, 72, 60, 177, 192, 210, 89, 171, 151, 47, 89, 60, 175, 46, 66, 8, 83, 17, 163, 106, 247, 182, 137, 19, 23, 45, 156, 56, 113, 206, 206, 229, 75, 55, 84, 40, 51, 162, 170, 97, 206, 60, 185, 167, 62, 61, 99, 230, 218, 162, 220, 170, 137, 125, 179, 183, 29, 219, 27, 137, 162, 66, 96, 250, 129, 67, 219, 122, 251, 150, 109, 106, 203, 203, 203, 46, 152, 62, 105, 249, 217, 59, 103, 107, 216, 16, 102, 112, 205, 56, 118, 229, 194, 190, 45, 23, 87, 53, 180, 52, 151, 214, 76, 90, 178, 120, 229, 149, 123, 119, 15, 212, 193, 85, 48, 118, 238, 60, 120, 236, 218, 254, 205, 253, 57, 49, 89, 197, 43, 87, 236, 94, 185, 114, 233, 169, 11, 183, 207, 236, 200, 130, 217, 18, 188, 111, 207, 222, 253, 167, 78, 78, 47, 9, 15, 78, 106, 219, 178, 126, 97, 99, 221, 218, 157, 39, 78, 95, 56, 184, 209, 9, 98, 137, 194, 174, 189, 91, 151, 207, 216, 190, 188, 167, 32, 58, 60, 46, 161, 172, 119, 250, 194, 25, 91, 79, 30, 57, 114, 246, 230, 246, 249, 130, 96, 5, 213, 23, 118, 174, 154, 53, 185, 57, 41, 41, 58, 56, 50, 62, 166, 107, 194, 198, 75, 183, 206, 95, 57, 118, 224, 196, 185, 67, 107, 162, 65, 242, 236, 107, 55, 206, 92, 50, 177, 58, 55, 45, 41, 49, 44, 48, 49, 107, 197, 209, 147, 23, 143, 239, 57, 125, 124, 255, 225, 99, 251, 150, 79, 6, 5, 171, 253, 138, 169, 211, 230, 79, 175, 205, 204, 204, 42, 172, 44, 109, 158, 185, 237, 216, 201, 125, 219, 119, 236, 60, 189, 255, 248, 158, 157, 171, 167, 155, 0, 21, 132, 206, 233, 159, 185, 122, 113, 94, 106, 98, 108, 94, 201, 196, 165, 187, 182, 109, 7, 162, 125, 251, 118, 30, 58, 190, 125, 253, 226, 126, 95, 160, 130, 172, 217, 189, 253, 11, 86, 180, 228, 39, 196, 23, 213, 229, 44, 218, 191, 123, 239, 190, 29, 59, 55, 95, 63, 114, 98, 255, 198, 77, 11, 167, 164, 2, 21, 84, 244, 117, 78, 93, 60, 175, 175, 169, 187, 185, 36, 62, 99, 238, 166, 173, 91, 215, 173, 219, 185, 97, 239, 229, 243, 167, 15, 239, 154, 222, 144, 14, 242, 196, 220, 166, 41, 221, 157, 173, 93, 117, 211, 235, 82, 107, 38, 245, 45, 94, 62, 127, 233, 234, 213, 135, 174, 94, 189, 114, 108, 115, 87, 67, 50, 80, 65, 66, 69, 81, 117, 78, 89, 121, 117, 71, 125, 79, 70, 81, 103, 197, 164, 165, 211, 230, 44, 94, 177, 98, 239, 141, 51, 123, 150, 76, 233, 12, 2, 42, 112, 204, 207, 206, 74, 75, 142, 77, 175, 72, 44, 78, 79, 140, 201, 236, 155, 221, 91, 213, 208, 82, 190, 110, 207, 198, 101, 51, 59, 10, 244, 129, 10, 12, 253, 67, 194, 195, 35, 35, 210, 146, 227, 115, 75, 242, 129, 33, 89, 30, 151, 16, 19, 17, 83, 187, 96, 118, 119, 83, 92, 148, 48, 80, 1, 155, 165, 119, 136, 131, 179, 79, 64, 112, 68, 86, 85, 73, 92, 100, 70, 78, 78, 98, 88, 144, 127, 97, 123, 117, 182, 159, 175, 14, 56, 186, 164, 141, 60, 173, 205, 109, 156, 220, 253, 34, 170, 187, 50, 50, 146, 83, 130, 2, 253, 131, 253, 83, 227, 98, 66, 221, 116, 89, 33, 177, 197, 103, 169, 166, 97, 102, 97, 237, 28, 18, 151, 146, 30, 235, 237, 98, 239, 17, 224, 101, 231, 228, 225, 231, 106, 192, 13, 75, 50, 188, 122, 202, 242, 26, 218, 54, 118, 193, 158, 158, 206, 14, 206, 118, 166, 230, 78, 182, 214, 86, 198, 226, 72, 137, 142, 73, 152, 95, 68, 76, 78, 81, 73, 93, 91, 91, 93, 75, 93, 65, 93, 73, 64, 86, 146, 7, 45, 101, 51, 50, 177, 241, 201, 168, 104, 138, 114, 114, 114, 72, 72, 49, 49, 162, 37, 106, 168, 98, 70, 54, 102, 38, 70, 102, 38, 86, 236, 178, 56, 51, 20, 61, 37, 184, 144, 178, 18, 9, 246, 2, 0, 140, 249, 44, 20, 196, 91, 75, 1, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130";

            string result = ImageToPngCsv(Properties.Resources.Moon32x32);

            Assert.AreEqual(expectedString, result);
        }

    }
}
